<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1">
	<title>Login</title>
	<link rel="stylesheet" href="css/auth.css">
</head>

<body>
	<div class="lowin lowin-purple">
		<div class="lowin-brand">
			<img src="images/kodinger.jpg" alt="logo">
		</div>
		<div class="lowin-wrapper">
			<div class="lowin-box lowin-login">
				<div class="lowin-box-inner">
						<p >Sign in to continue</p>
					    <p><span id="notice"></span></p>
						<div class="lowin-group">
							<label>账号 <a href="#" class="login-back-link">Sign in?</a></label>
							<input id="username" type="email" autocomplete="email" name="username" class="lowin-input">
						</div>
						<div class="lowin-group password-group">
							<label>密码 </label>
							<input id="password"type="password" name="password" autocomplete="current-password" class="lowin-input">
						</div>
						<button  name="login" onclick="login()" class="lowin-btn login-btn">
							Sign In
						</button>

						<div class="text-foot">
							<fieldset id="loginSelect">
							<td><input class ="select" name="whoLogin" type="radio" value="user" checked="checked"/>用户</td>
							<td><input class ="select" name="whoLogin" type="radio" value="admin" />管理员</td>
							<td><input class ="select" name="whoLogin" type="radio" value="maintainer" />维修员</td>
							</fieldset>
						</div>
				</div>
			</div>
		</div>
	</div>


</body>

<script src="js/jquery-3.3.1.js"></script>
<script type="text/javascript">
	var username = document.getElementById('username')
	var password = document.getElementById('password')
	var notice = document.getElementById('notice')

    function login(){
	    var loginSelect = $('input:radio:checked').val()
		if(loginSelect == "user"){
	        $.ajax({
				type:'POST',
				url:'user/login.do',
				data:{
				    userNum:username.value,
					userPassword:password.value
				},
				success:function(res){
				    if(res.status == 0){
                        window.location.href="userBackIndex.html"
					}
					if(res.status == 1){
				        notice.style.color="#ff6464"
                        notice.innerHTML=res.msg
					}
				}
			})
		}else if(loginSelect == "admin"){
            $.ajax({
                type:'POST',
                url:'admin/login.do',
                data:{
                    adminNum:username.value,
                    adminPassword:password.value
                },
                success:function(res){
                    if(res.status == 0){
                        window.location.href="adminBackIndex.html"
                    }
                    if(res.status == 1){
                        notice.style.color="#ff6464"
                        notice.innerHTML=res.msg
                    }
                }
            })
		}else if(loginSelect == "maintainer"){
            $.ajax({
                type:'POST',
                url:'maintainer/login.do',
                data:{
                    maintainerNum:username.value,
                    maintainerPassword:password.value
                },
                success:function(res){
                    if(res.status == 0){
                        window.location.href="maintainerBackIndex.html"
                    }
                    if(res.status == 1){
                        notice.style.color="#ff6464"
                        notice.innerHTML=res.msg
                    }
                }
            })
		}
    }

</script>
</html>